package com.googlecode.garbagecan.perf4jstudy.spring1;

import java.math.BigInteger;
import org.perf4j.aop.Profiled;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.googlecode.garbagecan.perf4jstudy.LogParserUtil;

public class Test {

	public static void main(String[] args) throws Exception {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/com/googlecode/garbagecan/perf4jstudy/spring1/spring.xml");
		Test t = (Test) applicationContext.getBean("test");

		for (int i = 0; i < 100; i++) {
			System.out.println("nextPrime() returned " + t.nextPrime());
			Thread.sleep(100);
		}

		for (int i = 0; i < 10; i++) {
			UserService userService = (UserService) applicationContext.getBean("userService");
			userService.test1();
			userService.test2();
			userService.test3();
		}

		System.out.println(LogParserUtil.parseLog2String("perf4j.log"));
	}
	private BigInteger currentPrime = new BigInteger("0");

	public void setCurrentPrime(BigInteger currentPrime) {
		this.currentPrime = currentPrime;
	}

	@Profiled
	public BigInteger nextPrime() {
		currentPrime = currentPrime.nextProbablePrime();
		return currentPrime;
	}
}
